<include file="Public/min-header" />
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";
</script>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.config.js" />
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.all.js" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">发布活动</h3>
                        <a href="{:U('Article/articleList')}" data-toggle="tooltip" title="" class="btn btn-primary pull-right" data-original-title="返回"><i class="fa fa-reply"></i></a>
                    </div>
                    <form class="form-horizontal" action="{:U('Article/aticleHandle')}" id="add_post" method="post">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">活动标题</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" value="{$info.title}" name="title">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">乡村区域</label>
                                <div class="col-sm-2">
                                    <select class="small form-control" name="area_id" id="area_id">
                                        <option value="0">选择乡村所属区域</option>
                                        <volist name="region" id="val">
                                        	<option value="{$val.id}" style="padding-left:{$val['level']*10}px" <if condition="$val['id'] eq $info['area_id']">selected</if>>{$val.name}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group information_images">
                            	<label class="control-label col-sm-2">活动相册</label>
                            	<div class="col-sm-8">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td>
                                    <foreach name="article_img" item="vo" key="k">
                                        <div style="width:300px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">
                                            <input type="hidden" value="{$vo['images']}" name="info_images[]">
                                            <a onclick="" href="{$vo['images']}" target="_blank"><img width="100" height="100" src="{$vo['images']}"></a><br>
                                            <a href="javascript:;" onclick="ClearPicArr2(this, '{$vo['id']}')">删除</a>
                                        </div>
                                    </foreach>
                                    <div class="goods_xc" style="width:300px; text-align:center; margin: 5px; display:inline-block;">
                                        <input type="hidden" name="info_images[]" value="" />
                                        <a href="javascript:;" onclick="GetUploadify(10, '', 'rural', 'call_back2');"><img src="/Public/images/add-button.jpg" width="100" height="100" /></a><br/>
                                        <a href="javascript:;">&nbsp;&nbsp;</a>
                                    </div>
                                    </td>
                                    </tr>
                                    </tbody>
                                </table>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="text" class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="abst" value="{$info.abst}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="text" class="col-sm-2 control-label">详细地址</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="address" value="{$info.address}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="text" class="col-sm-2 control-label">活动开始时间</label>
                                <div class="col-sm-8">
                                    <div class="input-prepend input-group">
                                        <span class="add-on input-group-addon">
                                            <i class="glyphicon glyphicon-calendar fa fa-calendar">
                                            </i>
                                        </span>
                                        <input type="text" class="form-control" id="activity_start_time" name="activity_start_time" value="{$info.activity_start_time|date=" Y-m-d ",###}">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="text" class="col-sm-2 control-label">活动结束时间</label>
                                <div class="col-sm-8">
                                    <div class="input-prepend input-group">
                                        <span class="add-on input-group-addon">
                                            <i class="glyphicon glyphicon-calendar fa fa-calendar">
                                            </i>
                                        </span>
                                        <input type="text" class="form-control" id="activity_end_time" name="activity_end_time" value="{$info.activity_end_time|date=" Y-m-d ",###}">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="text" class="col-sm-2 control-label">是否显示</label>
                                <div class="col-sm-5" style="margin-top:5px;">
                                    <div class="col-sm-2">
                                        <label>
                                            <input type="radio" name="is_open" value="1" <if condition="$info[is_open] eq 1"> checked="checked"</if>> 显示 </label>
                                    </div>
                                    <div class="col-sm-3">
                                        <label>
                                            <input type="radio" name="is_open" value="0" <if condition="$info[is_open] eq 0"> checked="checked"</if>> 不显示</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">活动内容</label>
                                <div class="col-sm-8">
                                    <textarea class="span12 ckeditor" id="post_content" name="content" title="">
                                        {$info.content}
                                    </textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">
                                    <input type="hidden" name="act" value="{$act}">
                                    <input type="hidden" name="article_id" value="{$info.article_id}">
                                </label>
                                <div class="col-sm-8">
                                    <button type="reset" class="btn btn-primary">重置</button>
                                    <button type="button" onclick="checkForm()" class="btn btn-info pull-right">提交</button>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer row">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
<script type="text/javascript">
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js 中
        var options = {
            zIndex: 999,
            initialFrameWidth: "100%", //初化宽度
            initialFrameHeight: 400, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign', //允许的最大字符数 'fullscreen',
            pasteplain: false,
            autoHeightEnabled: true,
            /*autotypeset: {
             mergeEmptyline: true, //合并空行
             removeClass: true, //去掉冗余的class
             removeEmptyline: false, //去掉空行
             textAlign: "left", //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
             imageBlockLine: 'center', //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
             pasteFilter: false, //根据规则过滤没事粘贴进来的内容
             clearFontSize: false, //去掉所有的内嵌字号，使用编辑器默认的字号
             clearFontFamily: false, //去掉所有的内嵌字体，使用编辑器默认的字体
             removeEmptyNode: false, //去掉空节点
             //可以去掉的标签
             removeTagNames: {
             "font": 1
             },
             indent: false, // 行首缩进
             indentValue: '0em' //行首缩进的大小
             }*/
        };
        editor = new UE.ui.Editor(options);
        editor.render("post_content");
        //编辑器初始化完成后设置#edui106_content,#edui93_content元素
        var timer = setInterval(function(){
            console.log('1');
            $('#edui106_content').css('height', '248px');
            $('#edui93_content').css('height', '248px');
            if($('#edui106_content').height() > 200 && $('#edui93_content').height() > 200 ){
                clearInterval(timer);
            }
        },1000);
    });
    $('#activity_start_time').daterangepicker({
        format: "YYYY-MM-DD",
        singleDatePicker: true,
        showDropdowns: true,
        minDate: '2016-01-01',
        maxDate: '2030-01-01',
        startDate: '{$info.activity_start_time|date="Y-m-d",###}',
        locale: {
            applyLabel: '确定',
            cancelLabel: '取消',
            fromLabel: '起始时间',
            toLabel: '结束时间',
            customRangeLabel: '自定义',
            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            firstDay: 1
        }
    });
	$('#activity_end_time').daterangepicker({
        format: "YYYY-MM-DD",
        singleDatePicker: true,
        showDropdowns: true,
        minDate: '2016-01-01',
        maxDate: '2030-01-01',
        startDate: '{$info.activity_end_time|date="Y-m-d",###}',
        locale: {
            applyLabel: '确定',
            cancelLabel: '取消',
            fromLabel: '起始时间',
            toLabel: '结束时间',
            customRangeLabel: '自定义',
            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            firstDay: 1
        }
    });
	function call_back2(paths) {
		console.log(paths);
        var last_div = $(".goods_xc:last").prop("outerHTML");
        for (i = 0; i < paths.length; i++) {
            $(".goods_xc:eq(0)").before(last_div); // 插入一个 新图片
            $(".goods_xc:eq(0)").find('a:eq(0)').attr('href', paths[i]).attr('onclick', '').attr('target', "_blank"); // 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src', paths[i]); // 修改他的图片路径
            $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick', "ClearPicArr2(this,'" + paths[i] + "')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
            ; // 设置隐藏域 要提交的值
        }
    }
	function ClearPicArr2(obj,id){
		if(window.confirm('确定要删除该图片吗？')){
			$.post("{:U('Rural/del_img')}",{id:id},function(data){
				if(data.code==200){
					$(obj).parent().remove();
					alert('删除成功');
				}else{
					alert('删除失败');
				}
			},'json');
		}	
	}
    function checkForm() {
        if ($('input[name="title"]').val() == '') {
            alert("请填写活动标题！");
            return false;
        }
        if ($('#cat_id').val() == '' || $('#cat_id').val() == 0) {
            alert("请选择活动类别！");
            return false;
        }
        if ($('#post_content').val() == '') {
            alert("请填写活动内容！");
            return false;
        }
        $('#add_post').submit();
    }
</script>
</body>
</html>
